package com.ahnchan.ContactsPlus;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;

public class FontSizeDialog extends AlertDialog {
	
	public static String CONTACTS = "CONTACTS";
	public static String GROUP = "GROUP";
	public static String COMPANY = "COMPANY";
	public static String FAVORITES = "FAVORITES";
	
	private ContactsPlusSetting setting;	// Properties
	
	private ListActivity mActivity;
	private String mClassName;
	
	private View mView;

	private static int mMaxFontSize = 45;
	
	private SeekBar mFontSizeBar;
	private TextView mFontSize;
	
	private SeekBar mIndexSizeBar;
	private TextView mIndexSize;
	
	public FontSizeDialog(Context context, ListActivity activity, String className) {
		super(context);
		mActivity = activity;
		mClassName  = className;
		
		setting = ContactsPlusSetting.instatnce();
		
		mView = LayoutInflater.from(context).inflate(R.layout.fontsize_dialog, null);
		setView(mView);
		
		// Font Size
		mFontSizeBar = (SeekBar) mView.findViewById(R.id.fontsize_seekbar);
		mFontSizeBar.setMax(mMaxFontSize);
		mFontSizeBar.setProgress(setting.getIntFontSize()-setting.getMinFontSize());
//		TextView result = (TextView)view.findViewById(R.id.fontsize_result);
//		result.setText(getString(R.string.fontsize_result) + setting.getIntFontSize() + " " + getString(R.string.fontsize_unit));
		mFontSizeBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
			public void onStopTrackingTouch(SeekBar seekBar) {
				// nothing
			}
			public void onStartTrackingTouch(SeekBar seekBar) {
				// nothing
			}
			public void onProgressChanged(SeekBar seekBar, int progress,
					boolean fromUser) {
				// Change Dialog text (Font Size)
//	    		View view = ContactsActivity.this.getLayoutInflater().inflate(R.layout.fontsize_dialog, null);
//	    		TextView result = (TextView)view.findViewById(R.id.fontsize_result);
//	    		result.setText(getString(R.string.fontsize_result) + seekBar.getProgress() + " " + getString(R.string.fontsize_unit));
//	    		result.postInvalidate();
					
				int iFontSize = seekBar.getProgress()+setting.getMinFontSize();
				
				// Change list font size
	    		if (CONTACTS.equals(mClassName)) {
	    			((ContactsActivity)mActivity).changeFontSize(iFontSize);
	    		} else if (GROUP.equals(mClassName)) {
	    			((GroupActivity)mActivity).changeFontSize(iFontSize);
	    		} else if (COMPANY.equals(mClassName)) {
	    			((CompanyActivity)mActivity).changeFontSize(iFontSize);
	    		} else if (FAVORITES.equals(mClassName)) {
	    			((FavoritesActivity)mActivity).changeFontSize(iFontSize);
	    		}
				//changeFontSize(seekBar.getProgress()+setting.getMinFontSize());
			}
		});

		// Index font size
		mIndexSizeBar = (SeekBar) mView.findViewById(R.id.fontsize_seekbar_index);
		mIndexSizeBar.setMax(mMaxFontSize);
		mIndexSizeBar.setProgress(setting.getIndexFontSize()-setting.getMinFontSize());
		mIndexSizeBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
			public void onStopTrackingTouch(SeekBar seekBar) {
				// nothing
			}
			public void onStartTrackingTouch(SeekBar seekBar) {
				// nothing
			}
			public void onProgressChanged(SeekBar seekBar, int progress,
					boolean fromUser) {
				
				int iFontSize = seekBar.getProgress()+setting.getMinFontSize();
				
				// Change list font size
	    		if (CONTACTS.equals(mClassName)) {
	    			((ContactsActivity)mActivity).changeIndexFontSize(iFontSize);
	    		} else if (GROUP.equals(mClassName)) {
	    			((GroupActivity)mActivity).changeIndexFontSize(iFontSize);
	    		} else if (COMPANY.equals(mClassName)) {
	    			((CompanyActivity)mActivity).changeIndexFontSize(iFontSize);
	    		} else if (FAVORITES.equals(mClassName)) {
	    			((FavoritesActivity)mActivity).changeIndexFontSize(iFontSize);
	    		}
	
				// Change list font size
				//changeIndexFontSize(seekBar.getProgress()+setting.getMinFontSize());
			}
		});
	}

}
